﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;

namespace Locations
{
    /// <summary>
    /// Interaction logic for Address.xaml
    /// </summary>
    public partial class Address : UserControl
    {
        private SalesManagerEntities _context = null;
        //private AddressDataContext _context = new AddressDataContext(Location.Properties.Settings.Default.SalesManagerConnectionString);
        //private CollectionViewSource _addressViewSource;

        public Address()
        {
            InitializeComponent();
        }

        public void SetContext(SalesManagerEntities context)
        {
            _context = context;
        }

        private void AddressControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (_context != null)
            {
                CollectionViewSource countryViewSource = (CollectionViewSource)FindResource("Country");
                var countryList = from c in _context.codeCountry.Include("States")
                                  orderby c.Name
                                  select c;
                countryViewSource.Source = countryList;
                countryViewSource.View.CurrentChanged += new EventHandler(View_CurrentChanged);

                //_addressViewSource = (CollectionViewSource)FindResource("Address");
                //_addressViewSource.Source = _context.tblAddress;
            }
        }

        void View_CurrentChanged(object sender, EventArgs e)
        {
        }

    }
}
